layui.use(['element', 'layer'], function(){
    var element = layui.element;
    var layer = layui.layer;
    
    //监听折叠
    element.on('collapse(test)', function(data){
      layer.msg('展开状态：'+ data.show);
    });
  });
  layui.use('table', function(){
    var table = layui.table;
    var util = layui.util;
    table.render({
      elem: '#repair_table'
      ,url:head+'/manager/getManagerList'
      ,method:'post'
      ,request: {
        pageName: 'pageNum' //页码的参数名称，默认：page
        ,limitName: 'pageSize' //每页数据量的参数名，默认：limit
      }
      ,toolbar: '#toolbarDemo'
      ,title: '用户数据表'
      ,cols: [[ 
        {field:'identity', title:'账号', width:'15%'}
        ,{field:'name', title:'姓名', width:'13%'}
        ,{field:'pName', title:'权限', width:'20%'}
        ,{field:'addUser', title:'添加管理员',width:'20%'}
        ,{field:'addTime', title:'添加时间', width:'20%', templet:function(d){return util.toDateString(d.addtime*1,"yyyy-MM-dd HH:mm")}}
        ,{field:'area', title:'区域',width:'7%', maxlength:'20'}
        ,{field:'isUsed', title:'是否使用',width:'10%', templet:function(d){if(d.isUsed == 1) return "是";else return "否"}}
        ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:'13%'}
      ]]
      ,page: true
    });
    
    
    //监听行工具事件
    table.on('tool(test)', function(obj){
      var data = obj.data;
      //console.log(obj)
      if(obj.event === 'change'){
        // layer.confirm('是否确定', function(index){
        //   obj.del();
        //   layer.close(index);
        //   //操作...
        // });
        var opid = getId();
        var chid = data.id;
        $.ajax({
          url:head+"/manager/changeManagerUsed?opid="+opid+"&chid="+chid,
          dataType:"json",
          type:"GET",
          success:function(redata){
            if(redata.code == 0){
              layer.msg("成功", {
                time: 1500});
                window.location.reload();
              }else{                
                layer.msg(redata.msg, {
                  time: 1500});
              }

          }
        })
      } else if(obj.event === 'detail'){
        // alert(data.id);
        // alert(data.studentiden);
        //弹出层
        layer.open({
          type: 2, 
          title:'详细信息',
          area: ['84%','86%'],
          offset:['5%','8%'],
          scrollbar: true,
          content: 'manager_manage_item.html?id='+data.id,//这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
          success: function(layero,index){
          
          }
        }); 
  
      }
    });
  });
  